package com.bjtime.hprinter.Fragments.attrs

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import com.bjtime.designer.attributes.ViewAttr
import com.bjtime.designer.widget.BaseLabelView
import com.bjtime.designer.widget.ImageView2
import com.bjtime.designer.widget.LineView2
import com.bjtime.hprinter.Fragments.designer.Attrs


class AttsPageAdapter (fm: FragmentManager) : FragmentPagerAdapter (fm) {

    var mFragements     : MutableList<Fragment>     = ArrayList<Fragment> ()
    var mNothing        : nothing?                  = null
    var mLineAtt        : line?                     = null
    var mImageAtt       : image?                    = null
    var mTextAtt        : text?                     = null
    var mQRCodeAtt      : qrcode?                   = null
    var mBarCodeAtt     : barcode?                  = null
    var mRectAtt        : nothing?                  = null

    init {
        mNothing = nothing.newInstance ()
        mLineAtt = line.newInstance ()
        mBarCodeAtt = barcode.newInstance()
        mQRCodeAtt = qrcode.newInstance()
        mTextAtt = text.newInstance()
        mImageAtt = image.newInstance()

        mFragements.add(mNothing as Fragment)
        mFragements.add(mLineAtt as Fragment)
        mFragements.add(mBarCodeAtt as Fragment)
        mFragements.add(mQRCodeAtt as Fragment)
        mFragements.add(mTextAtt as Fragment)
        mFragements.add(mImageAtt as Fragment)
    }


    override fun getItem(position: Int): Fragment {
        return mFragements?.get(position)
    }

    override fun getCount(): Int {
        return mFragements?.size
    }

    fun setView (v : BaseLabelView) {
        when (v.des_viewtype) {
            ViewAttr.VIEW_TYPE.QRCODE -> mQRCodeAtt!!.setView(v)
            ViewAttr.VIEW_TYPE.BARCODE -> mBarCodeAtt!!.setView(v)
            ViewAttr.VIEW_TYPE.TEXT -> mTextAtt!!.setView(v)
            ViewAttr.VIEW_TYPE.LINE -> mLineAtt!!.setView(v as LineView2)
            ViewAttr.VIEW_TYPE.IMAGE -> mImageAtt!!.setView(v as ImageView2)
        }
    }

}